<!DOCTYPE html>
<html lang="en">
<head>
    {include file="common/new_meta" /}
</head>
<body {if $meeting_id}class="join-result-body"{/if}>
    {if $Think.config.webSwitches.joinmeeting_header}
        {include file="common/new_header" /}
    {/if}
    <?php
        $lang = $config['language'];
        switch ($lang) {
            case 'zh-cn':
                $lang = 'zh-CN';
                $android_lang = 'zh_CN';
                $ios_lang = 'zh-Hans';
                break;
            case 'zh-tw':
                $lang = 'zh-TW';
                $android_lang = 'zh_TW';
                $ios_lang = 'zh-Hant';
                break;
            case 'ja-jp':
                $lang = 'ja';
                $android_lang = 'ja';
                $ios_lang = 'ja';
                break;
            case 'ko-kr':
                $lang = 'ko';
                $android_lang = 'ko';
                $ios_lang = 'ko';
                break;
            default:
                $lang = 'en-US';
                $android_lang = 'en';
                $ios_lang = 'en';
                break;
        }
    ?>

<div class="main-content {if $meeting_id}hidden{/if}">
    <div class="main-content-inner large-bottom">
        <input type="hidden" id="showMeetingIdForm" value="{$showMeetingIdForm}" />
        <input type="hidden" id="meeting-id-from-url" value="{$meeting_cid}" />
        <input type="hidden" id="meeting-id-from-url-pc" value="{$meeting_id}" />
        <input type="hidden" id="displayName" value="{$displayName}" />
        <div class="page-header">
            <h2 class="page-header-heading">{$Think.config.appWords.join_meeting[$config['language']]}</h2>
        </div>
        <div class="join-form hidden">
            <div class="form-container">
                <form action="" method="post" id="join-form">
                    <input type="hidden" id="client" value="{$client}" />
                    <div class="error-return-message">Error message.</div>
                    <div class="form-group">
                        <input type="text" name="meeting-id" id="meeting-id" maxlength="30" class="form-control" value="{$join}" placeholder="活动 ID或个人链接名称">
                        <span class="error-message"></span>
                        <span class="meeting-id-message">您的活动ID是一个9、10或11位数字</span>
                    </div>
                    <button class="btn-primary" type="submit">加入</button>
                </form>
            </div>
        </div>

        <div class="launching-msg-mobile hidden">
            <p>您的活动将在数秒内开始……</p>
        </div>

        <!-- <div class="launching-msg-android hidden">您的活动将在数秒内开始……</div> -->
        <div class="info-android hidden">
            <p>如果已安装了ON ZOOM应用，请单击“加入活动”。</p>
            <p>
                <a href="vymeetjoin://" class="btn-link-primary android-launch-link">加入活动</a>
            </p>
            <br>
            <p>如果是首次在此设备上使用ON ZOOM，请通过下面的“从ON ZOOM网站下载”下载应用。</p>
            <p class="enter-id-message hidden">在您安装ON ZOOM应用程序之后，输入活动ID：<span class="id-text"></span></p>
            <p><a href="https://www.vymeet.com/update/onzoom_v1.1.2.apk" class="btn-link-primary android-download-url">从ON ZOOM网站下载</a></p>

        </div>

        <!-- <div class="launching-msg-ios hidden">
            <p>您的活动将在数秒内开始……</p>
        </div> -->
        <div class="info-ios hidden">
            <p>如果已安装了ON ZOOM应用，请单击“加入活动”。</p>
            <p>
                <a href="vymeetjoin://" class="btn-link-primary ios-launch-link">加入活动</a>
            </p>
            <br>
            <p>如果是首次在此设备上使用ON ZOOM，请通过下面的“从AppStore下载”安装应用程序。</p>
            <p class="enter-id-message hidden">在您安装ON ZOOM应用程序之后，输入活动ID：<span class="id-text"></span></p>
            <a href="https://apps.apple.com/cn/app/id1500546957" class="btn-link-primary" target="_blank">从AppStore下载</a>

        </div>
    </div>
</div>


<div class="join-result-pc {if !$meeting_id}hidden{/if}">
    <div class="launch-meeting">
        <div class="launch-section">
            <div class="launch-message-container">
                <p class="launch-message start">启动中...</p>
                <p class="launch-message open">
                    如果您看到系统对话框，请单击<b>“打开 ...”</b>。
                </p>
                <p class="launch-message download">
                    如果浏览器没有任何提示<a id="launch_meeting" href="javascript:;" class="browser-join"> 点击此处 </a>发起活动，或下载并运行ON ZOOM。
                </p>



                {if $Think.config.downloadName.pc_windows}
                <p class="launch-message download-link">
                    <a href="{$Think.config.home_url}/update/{$Think.config.downloadName.pc_windows}" class="pc-download-link">Windows客户端下载</a>
                </p>
                {/if}
                {if $Think.config.downloadName.pc_mac}
                <p class="launch-message download-link">
                    <a href="{$Think.config.home_url}/update/{$Think.config.downloadName.pc_mac}" class="pc-download-link">Mac客户端下载</a>
                </p>
                {/if}
                {if $Think.config.edition == 'regular'}
                {if $Think.config.downloadName.pc_yhkylin}
                <p class="launch-message download-link">
                    <a href="{$Think.config.home_url}/kylin-update/{$Think.config.downloadName.pc_yhkylin}" class="pc-download-link">银河麒麟客户端下载</a>
                </p>
                {/if}
                {/if}
                {if $Think.config.downloadName.win_touch}
                <p class="launch-message download-link">
                    <a href="{$Think.config.home_url}/rooms-update/{$Think.config.downloadName.win_touch}" class="pc-download-link">Windows触屏终端下载</a>
                </p>
                {/if}
                <br>
                <p class="launch-message browser">
                    {if $peerName && $displayName && $PHPSESSID && $token}
                        如果无法下载或运行应用程序，<a href="{$encrypted_extranet}{$meeting_id}?peerName={$peerName}&displayName={$displayName}&PHPSESSID={$PHPSESSID}&token={$token}&lang={$lang}&weburl={$weburl}" class="browser-join">使用浏览器加入</a>。
                    {else /}
                        {if $meeting_id}
                            如果无法下载或运行应用程序，<a href="/admin/conference/joinmeeting?m={$meeting_id}&t=go" class="browser-join">使用浏览器加入</a>。
                        {else /}
                            如果无法下载或运行应用程序，<a href="/admin/conference/joinmeeting?m={$meeting_cid}&t=go" class="browser-join">使用浏览器加入</a>。
                        {/if}
                    {/if}
                   <!-- 如果无法下载或运行应用程序，<a href="https://v.vymeet.com:443/812244054?peerName=843212379&displayName=牛呵呵&PHPSESSID=7f1hbrb05nfg37i0trr3epnlj1&token=991a0a5f-e4d3-4d63-9599-c3f6749ae371&lang=zh-CN&weburl=https://my.local-vymeet.cn" class="browser-join">使用浏览器加入</a>。-->
                </p>
                <p class="download-info-text" style="display: none;" id="chrome-download">
                    <a href="https://www.vymeet.com/browser/ChromeSetup.exe" class="soft-link">
                        Windows版 Google Chrome 下载                        </a>
                    <br>
                    <a href="https://www.vymeet.com/browser/googlechrome.dmg" class="soft-link">
                        Mac版 Google Chrome 下载                        </a>
                    <br><br>
                </p>
            </div>
        </div>
    </div>
</div>

<div class="weixin-instruction hidden">
    <div class="header">
        <p class="first"><em>1</em>.轻触上面的菜单</p>
        <img src="/assets/img/new/join/boult.png" class="boult"/>
    </div>
    <div class="main android" align="center">
        <p class="second"><em>2</em>.点击“在浏览器打开”，然后您将成功加入活动</p>
        <img  src="/assets/img/new/join/android.png" class="choose"/>
    </div>
    <div class="main ios hidden" align="center">
        <p class="second"><em>2</em>.点击“在Safari打开”，然后您将成功加入活动<p></p></p>
        <img src="/assets/img/new/join/ios.png" class="choose" style="width: 68.8vw;">
    </div>
</div>


<script>
    // 加入活动逻辑
    $(document).ready(function(){
        // 判断系统是PC，安卓，iphone还是mac
        var ua = window.navigator.userAgent.toLowerCase();
        var isAndroid = ua && ua.indexOf('android') > 0;
        var isIOS = /iphone|ipad|ipod|ios/.test(ua);
        var isMac = ua && ua.indexOf('macintosh') > 0;
        var isPC = !isAndroid && !isIOS && !isMac;
        var isWeixin = ua && ua.indexOf('micromessenger') > 0;
        var isOpera = /opera|opr\/[\d]+/.test(ua);
        var isEdge = /edge\/(\d+)/.test(ua);
        var isChrome = !isOpera && !isEdge && /chrome/.test(ua) && /webkit/.test(ua);
        var meetingIdTouched = false;
        var showMeetingIdForm = $("#showMeetingIdForm").val();
        var pcSchemeUrl = '';
        var meetingIdFromUrl = $('#meeting-id-from-url').val();
        var meetingIdFromUrlPc = $("#meeting-id-from-url-pc").val();

        function launchSchemeInIframe() {
            $('#launch_scheme_frame').remove();
            var launchFrame = $('<iframe id="launch_scheme_frame" style="width:0;height:0;" frameborder="0" title="Inline Launch Frame"></iframe>');
            launchFrame.attr('src', pcSchemeUrl);
            launchFrame.appendTo(document.body);
        }

        if (meetingIdFromUrl) {
            if (isPC || isMac) {
                $("body").addClass("join-result-body");
                $('.main-content').hide();
                $('.join-result-pc').show();
                setTimeout(function(){
                    launchPcApp()
                },2000);
            }else{
                $('.enter-id-message .id-text').text(meetingIdFromUrl);
                $('.enter-id-message').show();
            }
        }

        if (meetingIdFromUrlPc) {
            if (!isPC && !isMac) {
                $("body").removeClass("join-result-body");
                $('.join-result-pc').hide();
                $('.main-content').show();
                $('.enter-id-message .id-text').text(meetingIdFromUrlPc);
                $('.enter-id-message').show();
                launchMobileApp();
            }
        }

        if (!isChrome) {
            $('.launch-message.browser').text("如果无法下载或运行应用程序，建议您使用 Google Chrome 浏览器加入活动。");
            $("#chrome-download").show();
        }

        if (isPC || isMac) {
            $('.join-form').show();
            /*if (isMac) {
                $('.pc-download-link').attr('href', 'https://www.vymeet.com/update/vymeet-mac-latest.dmg');
            }*/
            if (meetingIdFromUrlPc != '') {
                setTimeout(function(){
                    launchPcApp()
                },2000);
            }
        } else if (isWeixin) {
            $('body > div').hide();
            if (isIOS) {
                $('.weixin-instruction .main.android').hide();
                $('.weixin-instruction .main.ios').show();
            }
            $('.weixin-instruction').show();
            return
        } else if (isAndroid) {
            if (isWeixin) {
                layer.msg("微信中不支持加入活动，建议使用其他浏览器打开本链接");
                return;
            }

            if (showMeetingIdForm === '1') {
                $('.join-form').show();
            }else{
                // $('.launching-msg-android').show();
                $('.launching-msg-mobile').show();
                launchMobileApp();
            }
        } else if (isIOS) {
            if (showMeetingIdForm === '1') {
                $('.join-form').show();
            }else{
                // $('.launching-msg-ios').show();
                $('.launching-msg-mobile').show();
                launchMobileApp();
            }
        }

        $('#meeting-id').focus(function(e) {
            if ($(this).parent('.form-group').hasClass('has-error')) {
                clearError('meeting-id');
            }

            meetingIdTouched = true;
        })
        $('#meeting-id').blur(function(e) {
            if (meetingIdTouched) {
                validateMeetingId();
            }
        });

        $('#join-form').on('submit', function(e) {
            e.preventDefault();

            if (validateMeetingId()) {
                $("#btn-primary").attr("disabled", "disabled");

                var index = layer.load(0, {
                    shade: false
                }); //0代表加载的风格，支持0-2

                errorReturn("");

                var meetingId = $("#meeting-id").val();
                var client = $("#client").val();

                $.ajax({
                    url:'/admin/conference/joinmeeting',
                    data:'meeting_id='+meetingId+'&client='+client,
                    type:'post',
                    success:function(data){
                        layer.close(index);

                        $("#btn-primary").removeAttr("disabled");

                        if (data['code']==1) {
                            window.location.href=data['url'];
                        }else{
                            errorReturn(data['msg']);
                        }
                    }
                });

                return false;
            }

            return false;
        });


        //--------------------------------------------------------------


        // 点击此处，发起活动事件
        $("#launch_meeting").click(function(){
            launchPcApp();
        })

        function launchPcApp() {
            // vytalk://index?token=xxx 唤起程序并登陆
            if (isPC || isMac) {
                var pcSchemeUrl = '{$Think.config.pullupKeywords.pc}index';
                var displayName = $("#displayName").val();
                if (meetingIdFromUrlPc != '') {
                    pcSchemeUrl = '{$Think.config.pullupKeywords.pc}start/conference?cid=' + meetingIdFromUrlPc + '&displayName=' + displayName + '&weburl={$weburl}&lang={$lang}';
                }
                if (meetingIdFromUrl != '') {
                    pcSchemeUrl = '{$Think.config.pullupKeywords.pc}start/conference?cid=' + meetingIdFromUrl + '&displayName=' + displayName + '&weburl={$weburl}&lang={$lang}';
                }
                // window.location.href = pcSchemeUrl;
                $('#launch_scheme_frame').remove();
                var launchFrame = $('<iframe id="launch_scheme_frame" style="width:0;height:0;" frameborder="0" title="Inline Launch Frame"></iframe>');
                launchFrame.attr('src', pcSchemeUrl + '&time' + (new Date()).getTime());
                launchFrame.appendTo(document.body);
            }
        }

        function launchMobileApp() {
            var start = new Date().getTime();
            if (isAndroid) {
                var androidSchemeUrl = '{$Think.config.pullupKeywords.app_meeting}';
                if (meetingIdFromUrl) {
                    androidSchemeUrl = '{$Think.config.pullupKeywords.app_meetingin}?cid=' + meetingIdFromUrl + '&cp=null&weburl={$weburl}&lang={$android_lang}';
                }else if (meetingIdFromUrlPc) {
                    androidSchemeUrl = '{$Think.config.pullupKeywords.app_meetingin}?cid=' + meetingIdFromUrlPc + '&cp=null&weburl={$weburl}&lang={$android_lang}';
                }
                $('.android-launch-link').attr('href', androidSchemeUrl);
                // window.location.href = androidSchemeUrl;
            } else if (isIOS) {
                var iosSchemeUrl = '{$Think.config.pullupKeywords.app_meeting}';
                if (meetingIdFromUrl) {
                    iosSchemeUrl = '{$Think.config.pullupKeywords.app_meetingin}?cid=' + meetingIdFromUrl + '&weburl={$weburl}';
                }else if (meetingIdFromUrlPc) {
                    iosSchemeUrl = '{$Think.config.pullupKeywords.app_meetingin}?cid=' + meetingIdFromUrlPc + '&weburl={$weburl}';
                }
                $('.ios-launch-link').attr('href', iosSchemeUrl);
                // window.location.href = iosSchemeUrl;
            }

            window.setTimeout(function() {
                var now = new Date().getTime();
                // if (now - start < 3000) {
                if (isAndroid) {
                    // $('.launching-msg-android').hide();
                    $('.launching-msg-mobile').hide();
                    $('.info-android').show();
                    window.location.href = androidSchemeUrl;
                } else if (isIOS) {
                    // $('.launching-msg-ios').hide();
                    $('.launching-msg-mobile').hide();
                    $('.info-ios').show();
                    window.location.href = iosSchemeUrl;
                }
                // top.location.replace('itms-apps://itunes.apple.com/cn/app/id1170421091?mt=8');
                // }
            }, 2000);
        };

        function validateMeetingId() {
            clearError('meetingId');

            var meetingId = $('#meeting-id').val();
            var errorMessage = '';

            if (meetingId.trim() === '') {
                errorMessage = "请输入有效的活动ID";
            }

            if (errorMessage) {
                showError('meeting-id', errorMessage);
                return false;
            } else {
                return true;
            }
        }

        function showError(inputIdName, errorMessage) {
            var inputElement = $('#' + inputIdName);
            if (inputElement.length) {
                inputElement.next('.error-message').text(errorMessage);
                inputElement.parent('.form-group').addClass('has-error');
            }
        }

        function clearError(inputIdName) {
            var inputElement = $('#' + inputIdName);
            if (inputElement.length) {
                inputElement.next('.error-message').empty();
                inputElement.parent('.form-group').removeClass('has-error');
            }
        }
    });

    function errorReturn(msg) {
        if (msg == '') {
            $(".error-return-message").html("");
            $(".error-return-message").hide();
        }else{
            $(".error-return-message").html(msg);
            $(".error-return-message").show();
        }
    }
</script>
</body>
</html>